The present invention relates to a relocation format for linking, and in particular to a method of linking, a linker and a computer program product containing relocation instructions.
Linkers for producing executable programs are known. Generally speaking, a linker acts to link a number of object code modules to form a single executable program. Object code modules are usually generated from program source code modules, these modules being written in a high level language. An assembler/compiler reads each source code module and assembles and/or compiles the high level language of the source code module to produce an object code module. The assembler also generates a number of relocations which are used to combine the object code modules at link time in a linker.
The ELF (executable linking format) standard defines a convention for naming relocations belonging to a given section, e.g. rela.abc is relocation section of section space .abc. Standard relocations under the ELF format allow an offset in section data to be defined where patching is to occur and a symbol whose value is to be patched. A type field also exists which is used to describe the appropriate method of encoding the value of the symbol into the instruction or data of the section data being patched. According to the existing arrangements, the relocation type definitions are usually created on an ad hoc basis for each instruction set targeted. The 32 bit ELF standard allows only 256 distinct relocation types, so the same types are reascribed to different semantics for each instruction set.
The existing linkers each have to be set up to understand the particular semantics used for the type definitions in the relocations for each instruction set. Moreover, the relocation operations which can be defined by the relocations are limited in the existing ELF standard.
It is an object of the invention to provide novel relocations which extend the possibilities of the linker at link time, and which allow for more complex evaluations to be carried out at link time.
According to an aspect of the present invention there is provided a method of preparing an executable program from a plurality of object code modules, each module containing section data and relocation instructions, wherein the relocation instructions include special relocations which each include a type field identifying the nature of the function to be implemented by the special relocation, said function being selected from a plurality of arithmetic and logical functions, the method comprising: reading the section data and relocation instructions; determining from the type field of a special relocation the nature of the function to be implemented; and carrying out said selected arithmetic or logical function to generate a result value; and using said result value in a subsequent relocation operation defined by another of the relocation instructions.
Another aspect of, the invention provides a linker for preparing an executable program from a plurality of object code modules, each module containing section data and relocation instructions wherein the relocation instructions include special relocations which each include a type field identifying the nature of the function to be implemented by the special relocation, said function being selected from a plurality of arithmetic and logical functions, the linker comprising: a relocation module for reading said relocation instructions and carrying out relocation operations on the section data, including determining from the type field of a special relocation the nature of the function to be implemented; said relocation module comprising means for implementing calculations conveyed by the relocation instruction; a link store for holding a result value generated by carrying out said selected arithmetic or logical functions; and a program forming module for preparing the executable program using the relocated section data.
A further aspect of the invention provides a computer program product in the form of an object code module which contains sets of section data and relocation instructions, wherein the relocation instructions include special relocations which each include a type field identifying the nature of the function to be implemented by the special relocation, said function being selected from a plurality of arithmetic and logical functions, the computer program product being cooperable with the linker to cause execution of relocation operations by the linker so as to carry out said selected arithmetic or logical functions to generate a result value for use in subsequent relocation operations defined by others of the relocation instructions.
The special relocation can include at least one argument field for specifying a value to be used in the function identified in the type field. The special relocations can include a push operation which cause the value identified in the argument field to be placed in a store for subsequent use in an arithmetic or logical function of another special relocation. The use of a stack as a store is particularly useful, because values are pushed onto the top of the stack and retrieved from the top of the stack. It allows ordered semantics of the relocations to be made.
The argument field can convey the value which is to be used in the arithmetic or logical function conveyed by the same relocation.
The argument field can hold a symbol with points to a value in a symbol table, said value to be used in a subsequent arithmetic or logical function.
The result of the function can be used as a condition value to determine a condition which establishes which of a plurality of code sequences in the object module is to be included in an executable program.
The type field can hold an index for accessing a condition array which holds values in association with said indices, said values having been determined by earlier arithmetic or logical functions conveyed by relocations and being usable to establish conditions.
The special relocations can include a store relocation instruction which supplies the index and causes that top of stack value to be held in the condition array for subsequent use at the index. A further special relocation which can be provided is a fetch relocation instruction which allows the value to be recalled from the condition array and pushed onto the top of the stack, the index being supplied with the fetch relocation instruction.
The linker can include a section data module for holding section data to which the relocation instructions relate. Moreover, it can include a condition evaluator for examining a value (typically the top of the stack) at link time to determine whether or not a condition conveyed by the relocation instruction is satisfied. On this basis the relocation module is operable to instruct a section data module to conditionally include sequences of the section data in the executable program based on the evaluated condition.
A linker can have a parameter array for holding a set of parameters each associated with a respective index, the parameters identifying code sequences for possible inclusion in the executable program. Alternatively or additionally, the linker can have a symbol table which holds values in association with symbols, said symbols being conveyed by the relocation instructions. Alternatively and/or additionally, the linker can have a condition array which holds a plurality of values in association with respective indexes, said indexes being conveyed by the relocation instructions for recall of one of said plurality of values for use in determining a condition.